package nix.bs.test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.MessageFormat;

import org.junit.Test;

public class Demo1 {

	@Test
	public void fun1() {
		String str = MessageFormat.format("{0}或{1}错误！", "用户名", "密码");
		System.out.println(str);
	}

	@Test
	public void fun3() {
		long sum = 1;
		for (int i = 1; i <= 20; i++) {
			sum *= i;
		}
		System.out.println(sum);// 2432902008176640000
	}

	@Test
	public void fun4() {
		long sum = 1;
		for (int i = 1; i <= 21; i++) {
			sum *= i;
		}
		System.out.println(sum);// -4249290049419214848
	}

	@Test
	public void fun5() {
		BigInteger sum = BigInteger.valueOf(1);
		for (int i = 1; i <= 100; i++) {
			BigInteger bi = BigInteger.valueOf(i);
			sum = sum.multiply(bi);
		}
		System.out.println(sum);// 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
	}

	@Test
	public void fun2() {
		System.out.println(2.0 - 1.1);// 0.8999999999999999
	}

	@Test
	public void fun6() {
		BigDecimal d1 = new BigDecimal("2.0");
		BigDecimal d2 = new BigDecimal("1.1");
		BigDecimal d3 = d1.subtract(d2);
		System.out.println(d3);
	}

	// 易宝支付请求
	@Test
	public void fun7() {
		// 使用13参数+商户密钥生成Hmac
		String hmac = PaymentUtil.buildHmac("Buy", "10001126856", "123456",
				"0.01", "CNY", "", "", "",
				"http://localhost:8888/bs/OrderServlet?method=back", "", "",
				"BOC-NET-B2C", "1",
				"69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl");
		// 支付请求Url（13参数+Hmac）
		StringBuilder url = new StringBuilder("https://www.yeepay.com/app-merchant-proxy/node");
		url.append("?p0_Cmd=").append("Buy");
		url.append("&p1_MerId=").append("10001126856");
		url.append("&p2_Order=").append("123456");
		url.append("&p3_Amt=").append("0.01");
		url.append("&p4_Cur=").append("CNY");
		url.append("&p5_Pid=").append("");
		url.append("&p6_Pcat=").append("");
		url.append("&p7_Pdesc=").append("");
		url.append("&p8_Url=").append("http://localhost:8888/bs/OrderServlet?method=back");
		url.append("&p9_SAF=").append("");
		url.append("&pa_MP=").append("");
		url.append("&pd_FrpId=").append("BOC-NET-B2C");
		url.append("&pr_NeedResponse=").append("1");
		url.append("&hmac=").append(hmac);

		System.out.println(hmac);
		System.out.println(url);
		// https://www.yeepay.com/app-merchant-proxy/node?p0_Cmd=Buy&p1_MerId=10001126856&p2_Order=123456&p3_Amt=0.01&p4_Cur=CNY&p5_Pid=&p6_Pcat=&p7_Pdesc=&p8_Url=http://localhost:8888/bs/OrderServlet?method=back&p9_SAF=&pa_MP=&pd_FrpId=BOC-NET-B2C&pr_NeedResponse=1&hmac=204726f1212ff8d0736d8f3e46232aa9
	}
}
